package skills;

import loadsave.Memento;
import loadsave.loadsaveobject.Iterator;
import loadsave.loadsaveobject.LoadSaveObject;
import loadsave.loadsaveobject.LoadSaveObjectComposite;
import scheduler.DuplicateEventException;
import entity.Entity;
import handlers.RemoveTrapHandler;

/**
 * The purpose of RemoveTrapSkill is to provide a concrete
 * subtype of Skill.
 * 
 * The Skill class is responsible for implementing the
 * interface for execute(), which is responsible for
 * creating an interaction handler.
 * 
 * @author DangMH
 *
 */
public class RemoveTrapSkill extends Skill {
	
	public RemoveTrapSkill(String modelName) {
		super(modelName);
	}
	
	public RemoveTrapSkill() { }

	/**
	 * Responsible for creating an interaction handler.
	 * @throws DuplicateEventException 
	 */
	public void execute(Entity e) {
		(new RemoveTrapHandler(e) ).attemptTrapRemoval(getLevel());
		
	}

	public Memento getMemento() {
		return new Memento() {

			public LoadSaveObject getState() {
				LoadSaveObjectComposite ret = new LoadSaveObjectComposite( "", "RemoveTrapSkill" );
				Iterator<LoadSaveObject> iter = RemoveTrapSkill.super.getMemento().getState().getIterator();
				for( iter.init(); iter.hasNext(); iter.next() ) {
					ret.add( iter.getCurrKey().getValue(), iter.getCurrVal() );
				}
				
				return ret;
			}

			public void restoreState(LoadSaveObject lso) {
				RemoveTrapSkill.super.getMemento().restoreState( lso );
			}
		};
	}

	public RemoveTrapSkill clone() {
		return new RemoveTrapSkill(getName());
	}

}
